
//  ZBTableViewController.m
//  YouHui
//
//  Created by  on 11-11-24.
//  Copyright (c) 2011年 netease. All rights reserved.
//

#import "ZBTableViewController.h"
#import "ZBNavigationController.h"

@implementation ZBTableViewController

@dynamic zbNavigationItem;
@synthesize justPushed=_justPushed;
@synthesize justPoped=_justPoped;

-(ZBNavigationItem*)zbNavigationItem {
    if (!_zbNavigationItem) {
        _zbNavigationItem = [[ZBNavigationItem alloc] init];
        _zbNavigationItem.delegate = self;
    }
    return _zbNavigationItem;
}

-(void)dealloc {
    [_zbNavigationItem release];
    [super dealloc]; 
}

-(void)setTitle:(NSString *)title
{
    [super setTitle:title];
    self.zbNavigationItem.title = title;
}

-(void)zbBackButtonPressed {
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)upateNavigationItems {
    if (_zbNavigationItem.leftView) {
        self.navigationItem.leftBarButtonItem =[[[UIBarButtonItem alloc] initWithCustomView:_zbNavigationItem.leftView] autorelease];
    } else if (self.navigationController&&[self.navigationController.viewControllers objectAtIndex:0]!=self)
    {        
        UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
        [button setBackgroundImage:[UIImage imageNamed:@"naviBackButton.png"] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(zbBackButtonPressed) forControlEvents:UIControlEventTouchUpInside];
        button.frame = CGRectMake(0, 0, 60, 30);
        self.navigationItem.leftBarButtonItem =[[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
    } else {
        self.navigationItem.leftBarButtonItem = nil;  
    }
    
    if (_zbNavigationItem.titleView) {
        self.navigationItem.titleView =_zbNavigationItem.titleView;
    } else {
        self.navigationItem.titleView =_zbNavigationItem.titleLabel;       
    }
    
    if (_zbNavigationItem.rightView) {
        self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:_zbNavigationItem.rightView] autorelease];
    } else {
        self.navigationItem.rightBarButtonItem = nil;   
    }
}

-(void)navigationItemUpdated:(ZBNavigationItem*)item {
    [self upateNavigationItems];
}
-(void)loadingStart:(ZBNavigationItem*)item {
}
-(void)loadingComplete:(ZBNavigationItem*)item {
}

@end
